<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="renderer" content="webkit"/>
  <meta name="force-rendering" content="webkit"/>
  <!-- import CSS -->
  <link rel="stylesheet" href="../js/3rd/elementUi/index.css">
  <link rel="stylesheet" href="../css/pc.css">
  <script src="../js/3rd/elementUi/vue.js"></script>
  <script src="../js/3rd/jquery-3.1.1.min.js"></script>
</head>
<body>
  <div id="creatProject" class="admin" style="display:none">
    
	<el-container>
	  <el-aside class="sider-bar" id="siderbar">
      <div class="logo"><img src="../image/logo.jpg">来赚吧管理后台</div> 
	    <tp-siderbar title="发布项目"></tp-siderbar>
	  </el-aside>
	  <div class="right-content">
      <el-breadcrumb separator-class="el-icon-arrow-right" class="bread-bd">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>活动管理</el-breadcrumb-item>
      </el-breadcrumb>
      <div class="l-bd"> 
        <el-button type="primary" size="small" @click="submitProject">确认发布</el-button>
      </div>
      <div class="left-b">  		  
  		  <div class="input-group">
  	        <div class="title">*项目名称：</div>
  	        <div class="input">
  	        	<el-input  placeholder="请输入内容" v-model="projectData.name"></el-input>
  	        </div>			
  			<div class="clearfix"></div>
  		  </div>
  	      <div class="input-group">
  	        <div class="title">*项目归属：</div>
  	        <div class="input">
  	        	<template>
  				  <el-select v-model="projectData.belong" placeholder="请选择">
  				    <el-option
  				      v-for="item in options"
  				      :key="item.value"
  				      :label="item.label"
  				      :value="item.value">
  				    </el-option>
  				  </el-select>
  				</template>
  	        </div>			
  			  <div class="clearfix"></div>
  	      </div>
  	      <div class="input-group">
  	        <div class="title">*项目类别：</div>
  	        <div class="input" style="padding: 10px 0;">
  	        	<template>
      				  <el-radio v-model="projectData.category" label="2">合作型</el-radio>
      				  <el-radio v-model="projectData.category" label="1">平台型</el-radio>
      				</template>
  	        </div>			
  			    <div class="clearfix"></div>
  	      </div>
          <div class="input-group">
            <div class="title">合伙人姓名：</div>
            <div class="input" >
              <el-input  placeholder="请输入内容" v-model="projectData.userName" ></el-input>
            </div>      
            <div class="clearfix"></div>
          </div>
          <div class="input-group">
            <div class="title">直合伙人id：</div>
            <div class="input" >
              <el-input  placeholder="请输入内容" v-model="projectData.userFk" ></el-input>
            </div>      
            <div class="clearfix"></div>
          </div>
          <div class="input-group">
            <div class="title">直推人分成：</div>
            <div class="input" >
              <el-input  placeholder="请输入内容" v-model="projectData.percentDirect" type="number"></el-input>
            </div>      
            <div class="clearfix"></div>
          </div>
          <div class="input-group">
            <div class="title">间推人分成：</div>
            <div class="input" >
              <el-input  placeholder="请输入内容"  v-model="projectData.percentIndirect" type="number"></el-input>
            </div>      
            <div class="clearfix"></div>
          </div>
          <div class="input-group">
            <div class="title">办理人分成：</div>
            <div class="input" >
              <el-input  placeholder="请输入内容" v-model="projectData.percentMe" type="number"></el-input>
            </div>      
            <div class="clearfix"></div>
          </div>
          <div class="input-group">
            <div class="title">合作个人分成：</div>
            <div class="input" >
              <el-input  placeholder="请输入内容" v-model="projectData.percentPerson" type="number"></el-input>
            </div>      
            <div class="clearfix"></div>
          </div>
          <div class="input-group">
            <div class="title">平台分成：</div>
            <div class="input" >
              <el-input  placeholder="请输入内容" v-model="projectData.percentPlatform" type="number"></el-input>
            </div>      
            <div class="clearfix"></div>
          </div>
          <div class="input-group">
            <div class="title">项目类型：</div>
            <div class="input" >
              <el-input  placeholder="请输入内容" v-model="projectData.type"></el-input>
            </div>      
            <div class="clearfix"></div>
          </div>
  	      <div class="input-group">
  	        <div class="title">项目贡献值：</div>
  	        <div class="input" >
  	        	<el-input  placeholder="请输入内容" v-model="projectData.contributionValue"></el-input>
  	        </div>			
  			    <div class="clearfix"></div>
  	      </div>
  	      <div class="input-group">
  	        <div class="title">赚钱条件：</div>
  	        <div class="input">
  	        	<el-input  placeholder="请输入内容" v-model="projectData.handleCondition"></el-input>
  	        </div>			
  			    <div class="clearfix"></div>
  	      </div>
          <div class="input-group">
            <div class="title">赚钱方法：</div>
            <div class="input">
              <el-input  placeholder="请输入内容" v-model="projectData.makeMoney"></el-input>
            </div>      
            <div class="clearfix"></div>
          </div>
          <div class="input-group">
            <div class="title">备注：</div>
            <div class="input">
              <el-input  placeholder="请输入内容" v-model="projectData.doc"></el-input>
            </div>      
            <div class="clearfix"></div>
          </div>
          <div class="input-group">
            <div class="title">项目介绍：</div>
            <div class="input">
              <el-input
                type="textarea"
                :autosize="{ minRows: 2, maxRows: 4}"
                placeholder="项目详情"
                v-model="projectData.productIntroduce">
              </el-input>
            </div>      
            <div class="clearfix"></div>
          </div>
        </div>  

        <div class="right-b"> 
          <div class="title-group">
            <div class="title" style="float:left">项目业务(至少配置一项)：</div>
            <el-button type="success" size="small" style="float:left" @click="addBusiness">添加业务</el-button>
            <div class="clearfix"></div>
          </div>
          <div class="tr-input" v-for="productItem in projectData.projectItems"> 
            <el-input class="b" size="small" placeholder="业务名称" v-model="productItem.businessName"></el-input>
            <el-input class="b" size="small" placeholder="业务链接" v-model="productItem.link"></el-input>
            <el-input class="b" size="small" placeholder="利润" v-model="productItem.score"></el-input>
          </div>
        </div>
      </div>
      <div class="clearfix"></div>
	</el-container>



  </div>
</body>


  <!-- import JavaScript -->
  <script src="../js/3rd/elementUi/index.js"></script>
  <script src="../js/js/admin_siderbar.js"></script>
  <script src="../js/js/common.js"></script>
  <script>
   var token=getCookie("userToken");
   var userId=getCookie("userId");
   console.log(token)
   console.log(userId)
   if(!token||!userId){
      window.location.href = "/admin/login.html";
   }
   var projectData={
                      belong: "",
                      category: "1",
                      client: 3,
                      contributionValue: null,
                      doc: "",
                      handleCondition: "",
                      makeMoney: "",
                      name: "",
                      percentDirect: 0,
                      percentIndirect: 0,
                      percentMe: 0,
                      percentPerson: 0,
                      percentPlatform: 0,
                      productIntroduce: "",
                      projectItems: [
                        {
                          businessName: "",
                          link: "",
                          score: null
                        }
                      ],
                      token: "",
                      type: "",
                      userFk: 0,
                      userId: null,
                      userName: ""
                    }
   var options= [{
          value: 1,
          label: '普通项目'
        }, {
          value: 3,
          label: 'POS机项目'
        }, {
          value: 2,
          label: '信用卡项目'
        }];
    new Vue({
      el: '#creatProject',
      data: {
      	options:options,
        projectData:projectData,
        isSubmitProject:false
      },
      created:function(){
          this.projectData.token=token;
          this.projectData.userId=parseInt(userId);
          $("#creatProject").show();
      },
      methods:{
        addBusiness:function(){
          var business={businessName:'',link:'',score:''};
          this.projectData.projectItems.push(business);
          console.log(this.projectData)
        },
        submitProject:function(){
          if(this.isSubmitProject){
            return;
          }
          if(parseInt(this.projectData.percentDirect)+parseInt(this.projectData.percentIndirect)+parseInt(this.projectData.percentMe)+parseInt(this.projectData.percentPerson)+
            parseInt(this.projectData.percentPlatform)!==100){
            alert("分成必须总和为100");
            return
          }
          if(!this.projectData.name||!this.projectData.belong||!this.projectData.category){
              this.$alert('项目名，项目归属，项目类别为必填', '缺少信息', {
                confirmButtonText: '确定',
              });
            return;
          }      

          if(!this.projectData.projectItems[0].businessName||!this.projectData.projectItems[0].score){
              this.$alert('业务需要填一项', '缺少信息', {
                confirmButtonText: '确定',
              });
            return;
          }
          this.isSubmitProject=true;
          var url="/project/saveProject ";
          console.log(this.projectData);
          var data=this.projectData;
          pushData(url,data,function(res){
                this.isSubmitProject=false;
                console.log(res);
                if(res.state){
                  alert("发布成功")
                }else if(res.errorCode==008){
                	window.location.href = "/admin/login.html";
                }
                else{
                  alert(res.message)
                }
          }.bind(this))
        }

      }
      
    })
  </script>
</html>